package com.base.service.impl;

import java.util.List;

import com.base.bean.Depotquota;
import com.base.service.DepotquotaService;
import com.common.util.AbstractManager;
import com.common.util.PagerModel;

public class DepotquotaServiceImpl extends AbstractManager implements
		DepotquotaService {

	public void addDepotquota(Depotquota depotquota) {
		String hql = "select nvl(max(depotid),0) from Depotquota";
		
		long depotid = 0l;
		depotid = (Long) this.getHibernateTemplate().find(hql).get(0);
		depotid += 1l;
		
		depotquota.setDepotid(depotid);
		this.getHibernateTemplate().save(depotquota);
	}

	@SuppressWarnings("unchecked")
	public List<Depotquota> findAllDepotquota() {
		String hql = "from Depotquota order by depotid";
		return this.getHibernateTemplate().find(hql);
	}

	public Depotquota findDepotquota(long depotid) {
		return (Depotquota) this.getHibernateTemplate().load(Depotquota.class, depotid);
	}
	
	public Depotquota findDepotquota(String deptcode,long cardsubtypeno) {
		String hql = "from Depotquota dpq where dpq.department.deptcode = ? and dpq.cardsubtype.cardsubtypeno = ? and dpq.datadict.name = '激活'";
		return (Depotquota) this.getHibernateTemplate().find(hql, new Object[]{deptcode,cardsubtypeno}).get(0);
	}

	public PagerModel findDepotquotaForPager() {
		String hql = "from Depotquota order by depotid";
		return searchPaginated(hql);
	}

	public void removeDepotquota(long depotid) {
		Depotquota depotquota = null;
		depotquota = (Depotquota) this.getHibernateTemplate().load(Depotquota.class, depotid);
		if(depotquota != null) 
			this.getHibernateTemplate().delete(depotquota);
	}

	public void updateDepotquota(Depotquota depotquota) {
		this.getHibernateTemplate().update(depotquota);
	}

}
